package com.mabs.menu;

import com.mabs.service.PersonService;
import com.mabs.util.InputUtil;

public class Menu {
	static boolean b = true;

	public static void main(String[] args) {
		while (b) {
			showMenu();
			String option = InputUtil.getInput("请选择[1-6]:");
			switch (option) {
			case "1":
				PersonService.selectAllPersons();
				continueA();
				break;
			case "2":
				PersonService.insertPerson();
				continueA();
				break;
			case "3":
				PersonService.updatePerson();
				continueA();
				break;
			case "4":
				PersonService.deletePerson();
				continueA();
				break;
			case "5":
				showSelectMenu();
				String option1 = InputUtil.getInput("请选择[1-3]:");
				switch (option1) {
				case "1":
					PersonService.selectPersonById();
					break;
				case "2":
					PersonService.selectPersonByPhone();
					break;
				case "3":
					PersonService.selectPersonByName();
					break;
				default:
					System.out.println("输入错误...");
					break;
				}
				continueA();
				break;
			case "6":
				b = false;
				break;
			default:
				System.out.println("输入错误,请重新输入...");
				continueA();
			}
		}
	}

	public static void showMenu() {
		System.out.println("========= 欢迎使用手机通讯录 =========");
		System.out.println("1.查看全部");
		System.out.println("2.新增人员");
		System.out.println("3.修改信息");
		System.out.println("4.删除人员");
		System.out.println("5.查找人员");
		System.out.println("6.退出");
		System.out.println("======================================");
	}

	public static void showSelectMenu() {
		System.out.println("\t1.根据id查找人员");
		System.out.println("\t2.根据手机号查找人员");
		System.out.println("\t3.根据姓名模糊查找人员");
	}

	public static void continueA() {
		String exit = InputUtil.getInput("按任意键继续,按0退出...");
		if (exit.equals("0")) {
			b = false;
		}
	}
}
